//
//  BConversionCurrencyView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2019/1/4.
//  Copyright © 2019 guoshikeji. All rights reserved.
//

#import "BConversionCurrencyView.h"

#import "BCConversionResponse.h"

@interface BConversionCurrencyView ()

@property (nonatomic, strong) QMUITextField *currencyTF;

@end

@implementation BConversionCurrencyView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.layer.cornerRadius = 4.0;
        self.layer.borderColor = [UIColor qmui_colorWithHexString:@"#C2C2C2"].CGColor;
        self.layer.borderWidth = 1.0;
        //
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    //
    self.currencyTF = [QMUITextField new];
    self.currencyTF.textColor = [UIColor qmui_colorWithHexString:@"#000000"];
    self.currencyTF.adjustsFontSizeToFitWidth = true;
    self.currencyTF.font = [UIFont systemFontOfSize:19 weight:UIFontWeightSemibold];
    [self addSubview:self.currencyTF];
    [self.currencyTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(15.0);
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-15.0);
    }];
    self.currencyTF.enabled = false;
    self.currencyTF.placeholder = BCLocalizedKey(@"Exchange Amount");
    //
    self.currButton = [BConversionCurrencyButton new];
    [self addSubview:self.currButton];
    [self.currButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-8.0);
        make.centerY.mas_equalTo(self);
    }];
}


- (void)setConversionData:(BCConversionData *)conversionData {
    _conversionData = conversionData;
    //
    self.currButton.currencySign = conversionData.curr.sign;
    BOOL needArrow = conversionData.curr_list.count>1;
    self.currButton.needMoreArrorw = needArrow;
    //
    [self.currencyTF mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-CGRectGetWidth(self.currButton.frame)-25.0);
    }];
}


- (void)setCurrencyAmount:(NSString *)currencyAmount {
    _currencyAmount = currencyAmount;
    //
    self.currencyTF.text = currencyAmount;
}


@end
